/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.ProcessMonitor;
import com.sasis.model.WrProcess;
import com.sasis.dao.WrProcessDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class WrProcessDaoiBatis extends BaseDaoiBATIS implements WrProcessDao {

    /**
     * @see com.sasis.dao.WrProcessDao#getWrProcesss(com.sasis.model.WrProcess)
     */
    public List getWrProcesss(final WrProcess wrProcess) {
          return getSqlMapClientTemplate().queryForList("getWrProcesss", wrProcess);
    }

    /**
     * @see com.sasis.dao.WrProcessDao#getWrProcess(Integer id)
     */
    public WrProcess getWrProcess(Integer id) {
        WrProcess wrProcess = (WrProcess) getSqlMapClientTemplate().queryForObject("getWrProcess", id);

        //if (wrProcess == null) {
            //throw new ObjectRetrievalFailureException(WrProcess.class, id);
        //}

        return wrProcess;
    }

    /**
     * @see com.sasis.dao.WrProcessDao#saveWrProcess(WrProcess wrProcess)
     */    
    public int saveWrProcess(final WrProcess wrProcess) {
        Integer id = wrProcess.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addWrProcess", wrProcess);
        } else {
            getSqlMapClientTemplate().update("updateWrProcess", wrProcess);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(WrProcess.class, id);
        }
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.WrProcessDao#removeWrProcess(Integer id)
     */
    public void removeWrProcess(WrProcess wrProcess) {
        getSqlMapClientTemplate().update("deleteWrProcess",  wrProcess);
    }

	public List getProcessMonitors(ProcessMonitor processMonitor) {
		// TODO Auto-generated method stub
		return getSqlMapClientTemplate().queryForList("getProcessMonitors", processMonitor);
	}
}
